package example.com.widgetdemo;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;

/**
 * Created by qiaoshouqing on 2017/10/23.
 */

public class Utility {

    public static String getMottoText(Context context) {
        SharedPreferences share = context.getSharedPreferences("motto", Activity.MODE_WORLD_READABLE);
        return share.getString("mottotext", context.getResources().getString(R.string.motto));
    }

    public static int getMottoBg(Context context) {
        SharedPreferences share = context.getSharedPreferences("motto", Activity.MODE_WORLD_READABLE);
        return share.getInt("mottobg", R.drawable.bg_red);
    }

    public static void saveMottoText(Context context, String motto) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("motto", Context.MODE_PRIVATE); //私有数据
        SharedPreferences.Editor editor = sharedPreferences.edit();//获取编辑器
        editor.putString("mottotext", motto);
        editor.apply();
    }

    public static void saveMottoBg(Context context, int drawableResource) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("motto", Context.MODE_PRIVATE); //私有数据
        SharedPreferences.Editor editor = sharedPreferences.edit();//获取编辑器
        editor.putInt("mottobg", drawableResource);
        editor.apply();
    }
}
